<?php
namespace Home\Controller;
use Think\Controller;
class CatController extends CommonController{
	public function index($id)
	{
		$id = intval($_GET['id']);
		if(!$id){
			return $this->error('ID不存在');
		}
		$nav = D("Menu")->find($id);
		if(!$nav || $nav['status'] != 1){
			return $this->error('栏目ID不存在或者状态不为正常');
		}
		$advNews = D("PositionContent")->select(['status'=>1,'position_id'=>3],2);
		$rankNews = $this->getRanks();
		$pageSize = 2;
		$page = $_REQUEST['p'] ? $_REQUEST['p'] : 1;
		$conds = [
			'status'=>1,
			'thumb'=>['neq',''],
			'catid'=>$id,
		];
		$News = D("News")->getNews($conds,$page,$pageSize);
		$count = D("News")->getNewsCount($conds);
		$res = New \Think\Page($count,$pageSize);
		$pageres = $res->show();
		// var_dump($page);die;
		$this->assign('result',[
    			'advNews'=>$advNews,
    			'rankNews'=>$rankNews,
    			'catId'=>$id,
    			'listNews'=> $News,
    			'pageres'=>$pageres,
    			]);
		$this->display();
	}
}